/**
 * 
 */
package org.insia.smartposse.xfire.service;

import java.util.ArrayList;
import java.util.List;

import org.insia.smartposse.config.DAOFactory;
import org.insia.smartposse.metier.Company;
import org.insia.smartposse.metier.Project;
import org.insia.smartposse.metier.webservice.LightCompany;
import org.insia.smartposse.metier.webservice.LightProject;
import org.insia.smartposse.xfire.iservice.ICompanyService;

/**
 * @author raguerri
 * @since 18 avr. 07
 * @version 0.0.1
 * 
 */
public class CompanyService implements ICompanyService {

	/* (non-Javadoc)
	 * @see org.insia.smartposse.xfire.iservice.ICompanyService#get(long)
	 */
	public LightCompany get(long id) {
		LightCompany lcomp = null;
		try {
			Company comp = DAOFactory.getCompanyDAO().get(id);
			lcomp = comp.setLight();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return lcomp;
	}

	/* (non-Javadoc)
	 * @see org.insia.smartposse.xfire.iservice.ICompanyService#getProjects(long)
	 */
	public List<LightProject> getProjects(int company_id) {
		List<LightProject> lproj = new ArrayList<LightProject>();
		try {
			List<Project> projs = DAOFactory.getProjectDAO().getFrom(company_id);
			for (Project project : projs) {
				lproj.add(project.setLight());
			}
		}catch (Exception e) {
			e.printStackTrace();
		}
		return lproj;
	}

	public LightCompany createLightCompany(LightCompany lcompany) {
		return DAOFactory.getCompanyDAO().createLightCompany(lcompany);
	}

	public LightCompany updateLightCompany(LightCompany lcompany) {
		return DAOFactory.getCompanyDAO().updateLightCompany(lcompany);
	}

}
